package com.spc.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.spc.constant.MessageConstant;
import com.spc.entity.*;
import com.spc.entity.Result;
import com.spc.pojo.Heart;
import com.spc.pojo.HeartChoose;
import com.spc.service.HealthAssessmentService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/health")
public class HealthAssessmentController {

    @Reference
    private HealthAssessmentService healthAssessmentService;

    //分页查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){


        PageResult pageResult = healthAssessmentService.findPage(queryPageBean);

        return pageResult;

    }

    //根据id查询对应的数据，进行数据回显
    @RequestMapping("/findById")
    public com.spc.entity.Result findById(Integer id){

        try {
            Heart heart = healthAssessmentService.findById(id);
            return new Result(true, MessageConstant.QUERY_HEART_SUCCESS,heart);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.QUERY_HEART_FAIL);
        }
    }

    //根据用户id和表单数据修改数据
    @RequestMapping("/edit")
    public Result edit(@RequestBody Heart heart){

        try {
            healthAssessmentService.edit(heart);
            return new Result(true, MessageConstant.EDIT_HEART_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.EDIT_HEART_FAIL);
        }
    }

    //根据用户id删除数据
    @RequestMapping("/delete")
    public Result delete(Integer id){
        try {
            healthAssessmentService.delete(id);
            return new Result(true, MessageConstant.DELETE_HEART_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.DELETE_HEART_FAIL);
        }
    }

    //查询所有的心理测评内容
    @RequestMapping("/findAll")
    public Result findAll(){

    java.util.List<HeartChoose> list =  healthAssessmentService.findAll();
    return new Result(true,"",list);
    }
}
